const { DataTypes } = require('sequelize');
const seq = require('../db/seq');

const Chat = seq.define('Chat', ({
    chat_id: {
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4, // 自动生成 UUID
        primaryKey: true,
        allowNull: false,
        comment: '聊天记录ID',
    },
    senderId: {
        type: DataTypes.UUID,
        allowNull: false,
        references: {
            model: 'users', // 关联 User 表
            key: 'user_id',
        },
        onDelete: 'CASCADE',
        comment: '消息发送者ID',
    },
    receiverId: {
        type: DataTypes.UUID,
        allowNull: false,
        references: {
            model: 'users',
            key: 'user_id',
        },
        onDelete: 'CASCADE',
        comment: '消息接收者ID',
    },
    type: {
        type: DataTypes.INTEGER,
        allowNull: false,
        comment: "聊天表类型"
    },
    message: {
        type: DataTypes.TEXT,
        allowNull: false,
        comment: '聊天消息内容',
    }
}

));

module.exports = Chat;